﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using LinkCard.AdminCP.Common;
using LinkCard.Dao;
using LinkCard.Model;

namespace LinkCard.ShopCP.Sell
{
    public partial class SellSucc : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Int64 nPaymentID = ConvertUtility.ToInt64(Request.QueryString["PayLogID"]);
                var view = Request.QueryString["view"].ToString();
                if (view != "")
                {
                    if (view == "view")
                    {
                        errorMessage.Visible = false;
                    }
                }
                if (nPaymentID > 0)
                {
                    var db = new TopLinkEntities();
                    var _payLog = db.PayLog.Where(t => t.PayID == nPaymentID).FirstOrDefault();
                    if (_payLog != null)
                    {
                        Int64 nCustomerID = ConvertUtility.ToInt64(_payLog.CustomerID);
                        Int64 nSupplierID = ConvertUtility.ToInt64(_payLog.SupplierID);
                        var _customer = db.Customers.Where(t => t.CustomerID == nCustomerID).FirstOrDefault();
                        var _supplier = db.Supplier.Where(t => t.SupplierID == nSupplierID).FirstOrDefault();

                        this.PaymentID.Text = nPaymentID.ToString();
                        this.PaymentDate.Text = Convert.ToDateTime(_payLog.PayDate).ToShortDateString();
                        this.CardNumber.Text = _customer.CardNumber.ToString();
                        this.FullName.Text = _customer.Fullname.ToString();

                        if (_payLog.PayMethod == 0)
                        { //0:tien mat, 1: the ngan hang, 2: doi diem
                            this.PaymentMethod.Text = "Tiền mặt";
                            this.ByCash.Text = Utility.sDecimal(ConvertUtility.ToDecimal(_payLog.PayAmount.ToString()));
                            this.ByPoint.Text = "0";
                        }
                        else if (_payLog.PayMethod == 1)
                        {
                            this.PaymentMethod.Text = "Thẻ Ngân hàng";
                            this.ByCash.Text = _payLog.PayAmount.ToString();
                            this.ByPoint.Text = "0";
                        }
                        else if (_payLog.PayMethod == 2)
                        {
                            this.PaymentMethod.Text = "Điểm LinkCard";
                            this.ByCash.Text = "0";
                            this.ByPoint.Text = _payLog.PayAmount.ToString();
                        }

                        this.PointTemp.Text = _payLog.PayPointAdd.ToString();
                        this.Point.Text = _customer.Point.ToString();
                        this.PointBefore.Text = _payLog.CustomerPointBefore.ToString();
                        this.SupplierName.Text = _supplier.Name.ToString();
                    }
                    else
                    {
                        errorMessage.InnerText = "Không tồn tại Giao dịch này";
                        errorMessage.Visible = true;
                    }
                }

            }
        }
    }
}